<?php

namespace extend\oss;

use OSS\OssClient;
use OSS\Core\OssException;

class Oss extends Base
{
    public function checkFile($path)
    {
        $config = $this->config;
        try {
            $ossClient = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint']);
            return $ossClient->doesObjectExist($config['bucket'], $path);
        } catch (OssException $e) {
            return $e->getMessage();
        }
    }

    public function deleteFile($path)
    {
        $config = $this->config;
        try {
            $ossClient = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint']);
            $ossClient->deleteObject($config['bucket'], $path);
            return true;
        } catch (OssException $e) {
            return $e->getMessage();
        }
    }

}